﻿@model qltscd.Models.ScreenClient.KScreenClient

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/Modules/_LayoutDanhMucNhapLieu.cshtml";
}
<script>
    function confirmXoa() {
        var idK = document.getElementById('idK').value;
        if (idK == null || idK == '-1') {
            alert("Chọn kiểu trước");
        } else {
            if (confirm("Bạn có muốn xóa kiểu này?")) {
                document.location = "/QuanLyThietBi/Kieu/XoaKieu?id=" + idK;
            }
        }
    }

    function confirmSua() {
        var idK = document.getElementById('idK').value;
        if (idK == null || idK == '-1') {
            alert("Chọn kiểu trước");
        } else {
            document.location = "/QuanLyThietBi/Kieu/SuaKieu?id=" + idK;
        }
    }

    function onCheck(id) {
        document.getElementById('idK').value = id;
    }
</script>

<h2>Kiểu (Model)</h2>
<input type="hidden" value="-1" id="idK" name="idK"/>
@{
    Html.Telerik().Grid(Model.DSKieu)
    .Name("grdDSK")
    .DataKeys(keys => keys.Add(c => c.IdentityKieu))
    .Resizable(r => r.Columns(true))
    .Reorderable(r => r.Columns(true))
    .Sortable()
    .Pageable(paging => paging.Enabled(true).Style(GridPagerStyles.NextPreviousAndInput).PageSize(15))
    //.Editable(editing => editing.Mode(GridEditMode.InCell))
    .ToolBar(t => {
        t.Custom()
            .Action("Create", "Kieu")
            .ButtonType(GridButtonType.ImageAndText)
            .ImageHtmlAttributes(new { @class = "t-icon t-add" })
            .Text("Thêm kiểu");
        //t.SubmitChanges().ButtonType(GridButtonType.ImageAndText).SaveText("Lưu").CancelText("Hủy bỏ");
        t.Custom()
           .Text("Xóa kiểu")
           .ButtonType(GridButtonType.ImageAndText)
           .Url("#")
           .HtmlAttributes(new { @onclick = "confirmXoa()" })
           .ImageHtmlAttributes(new { @style = "background-image: url('./../../../../../QuanLyThietBi/Content/Images/cross.png')" });
        t.Custom()
           .Text("Sửa kiểu")
           .ButtonType(GridButtonType.ImageAndText)
           .Url("#")
           .HtmlAttributes(new { @onclick = "confirmSua()" })
           .ImageHtmlAttributes(new { @style = "background-image: url('./../../../../../QuanLyThietBi/Content/Images/hammer.png')" });
        t.Custom()
            .Text("In PDF")
            .Action("ShowPdf", "kieu")
            .ButtonType(GridButtonType.ImageAndText)
            .ImageHtmlAttributes(new
            {
                @style = "background-image: url('./../../../../../QuanLyThietBi/Content/Images/printer.png');"
            });
        t.Custom()
            .Text("Xuất Excel")
            .Action("ExportToExcel", "kieu")
            .ButtonType(GridButtonType.ImageAndText)
            .ImageHtmlAttributes(new
            {
                @style = "background-image: url('./../../../../../QuanLyThietBi/Content/Images/printer.png');"
            });
    })
    .DataBinding(databinding => {
        databinding.Server()
            .Select("Index", "Kieu");
        databinding.Ajax()
            .Select("_Index", "Kieu")
            .Insert("_Insert", "Kieu")
            .Delete("_Delete", "Kieu")
            .Update("_Update", "Kieu");
    })
    .Columns(column => {
        column.Template(
               @<text>
                <input name="checkedRecords" type="radio" title="checkedRecords" value="@item.IdentityKieu" onclick="onCheck(@item.IdentityKieu)"/>
            </text>)
               .ClientTemplate("<input type='radio' name='checkedRecords' value='<#=IdentityKieu#>' onclick='onCheck(<#=IdentityKieu#>)'/>")
               .Width(30);
        column.Bound(o => o.MaKieu).Title("Mã kiểu").Width(50);
           @* .Template(@<text> <span onclick="openDetailsWindow('@item.IdentityKieu')">@item.MaKieu</span>
    </text>)
            .ClientTemplate("<span onclick='openDetailsWindow('<#=IdentityKieu#>')'><#=MaKieu#></span>")*@
           
        column.Bound(o => o.TenChungLoai).Title("Chủng loại");
        column.Bound(o => o.TenHangSanXuat).Title("Hãng sản xuất");
        column.Bound(o => o.TenKieu).Title("Tên kiểu").Width(300);
        //column.Command(c => {
        //            c.Custom("Delete")
        //            .ButtonType(GridButtonType.Image)
        //            .Action("Delete", "Kieu")
        //            .ImageHtmlAttributes(new { @class = "t-icon t-delete" });     
        //        })    
        //    .Width(50);
    })
    .Render();
    }
    <script type="text/javascript">
        function openDetailsWindow(id) {
            var url = "/QuanLyThietBi/Kieu/ThongTinKieu/" + id;
            var windowElement = $.telerik.window.create({
                title: 'Thông tin kiểu',
                actions: ["Refresh", "Maximize", "Close"],
                contentUrl: url,
                modal: true,
                resizable: true,
                draggable: true,
                scrollable: true,
                visible: false,
                width: 1000,
                height: 650,
                id: 'detailsview',
                name: 'detailsview',
                onClose: function () {
                    document.location = document.location;
                }
            });
            var w = $(windowElement).data("tWindow");
            w.center();
            w.open();
        }
</script>